<!--字典项页-->
<template>
  <div style="background-color: #fff;padding: 10px 20px">
    <span style="line-height: 60px;font-size:20px;">字典项管理</span>
    <el-button type="primary" style="float: right;margin-top: 13px" @click="goBank">返回</el-button>
  </div>
<!--字典项搜索卡片-->
  <el-card  style="margin:20px;height: 70px;">
    <el-form :inline="true">
      <el-form-item label="字典项名称">
        <el-input placeholder="请输入" v-model="searchForm.label"> </el-input>
      </el-form-item>
      <el-form-item>
        <el-button  @click="resetSearch">重置</el-button>
        <el-button type="primary" @click="selectDictOption">搜索</el-button>
      </el-form-item>
    </el-form>
  </el-card>
  <el-card style="margin:20px;">
  <div style="margin:10px 0px 40px 10px;">
    字典项列表
    <el-button type="primary" style="float: right;margin-top:-3px;">新增字典项</el-button>
  </div>
    <el-table :data="dictOptionArr">
      <el-table-column type="index" label="编号" width="80px" align="center"></el-table-column>
      <el-table-column prop="label" label="字典项名称"  align="center"></el-table-column>
      <el-table-column prop="value" label="字典项值"  align="center"></el-table-column>
      <el-table-column prop="sort" label="字典项排序"  align="center"></el-table-column>
      <el-table-column prop="remark" label="备注信息"  align="center"></el-table-column>
      <el-table-column prop="createTime" label="创建时间"  align="center"></el-table-column>
      <el-table-column  label="操作"  align="center">
        <template #default="scope">
          <el-button type="primary" link @click="editDictOption(scope.row.id)"> 编辑</el-button>
          <el-button type="primary" link @click="deleteDictOption(scope.row.id)">删除</el-button>        </template>
      </el-table-column>
    </el-table>
  </el-card>

<!--保存字典项弹窗-->
  <el-dialog>
    <el-form :title="dialogTitle" v-model="dialogVisible" style="width: 1000px;padding:40px;">
      <el-form-item label="字典项名称">
        <el-input placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="字典项值">
        <el-input placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="字典项排序">
        <el-input placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="备注信息">
        <el-input placeholder="请输入"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button>取消</el-button>
      <el-button type="primary">保存</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import {onMounted, ref} from "vue";
import router from "@/router";
import qs from "qs";
import axios from "axios";
import {ElMessage} from "element-plus";

const dialogTitle = ref('新增字典项');
const dialogVisible = ref(true);
const dictOptionArr=ref([]);
const goBank =()=>{
  router.push('/dict')
}
// 获取url中的查询字符串参数 http://localhost:9090/dictOption?id=105
const dictId = new URLSearchParams(window.location.search).get('id');
// 定义变量来保存搜索条件
const searchForm = ref({label:'',dictId:dictId})

const selectDictOption=()=>{{
  let data = qs.stringify(searchForm.value)
  axios.get(BASE_URL+'/v1/dictoption/select?'+data)
      .then((response)=>{
        if(response.data.code===2000){
          dictOptionArr.value=response.data.data;
        }else{
          ElMessage.error(response.data.msg);
        }
      })
}}
onMounted(()=>{
  // 注意：这里不能清空字典id ，否则不知道查那个字典的字典项，所有的字典项都会被查出来
  selectDictOption();
  selectDictOption();
})
// 定义重置搜索的方法
const resetSearch=()=>{
  searchForm.value={label:'',dictId:dictId};

}

</script>

<style scoped>

</style>